//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using Content = CommunityServer.Components.Content;

using CommunityServer.Controls;
using CommunityServer.Blogs.Components;
namespace CommunityServer.Blogs.Controls
{
    /// <summary>
	/// A ContentPart loads content from the database 
	/// (much simplified from CMS, more can be moved here later)
	/// </summary>
	[PersistChildren(true)]
	[ParseChildren(false)]
    public class BlogContentPart : CommunityServer.Controls.ContentPart
	{
		
        private bool _useSectionID = false;
		

		
		/// <summary>
		///  the content to display from database, by name
		/// </summary>
		public override string ContentName
		{
            get
            {
                if (_useSectionID)
                {
                    string appKey = CSContext.Current.ApplicationKey;
                    

                    CommunityServer.Blogs.Components.Weblog weblog = Weblogs.GetWeblog(appKey, true);
                    return weblog.SectionID + base.ContentName;

                }
                return base.ContentName;

            }
            set { base.ContentName = value; }
		}
        public bool UseSectionID
        {
            get { return _useSectionID; }
            set { _useSectionID = value; }
        }
        protected override bool CanUserEdit()
        {
            string appKey = CSContext.Current.ApplicationKey;


            CommunityServer.Blogs.Components.Weblog weblog = Weblogs.GetWeblog(appKey, true);
            return Permissions.ValidatePermissions(weblog, Permission.Post, CSContext.Current.User);
        }
       
	}
}
